namespace Test.DataAccess.EF.SqlServer.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class _001 : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Admin",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 50),
                        IsSuperAdmin = c.Boolean(nullable: false),
                        UserName = c.String(nullable: false, maxLength: 50),
                        Password = c.String(nullable: false, maxLength: 100),
                        TrueName = c.String(nullable: false, maxLength: 50),
                        Phone = c.String(maxLength: 50),
                        Email = c.String(maxLength: 200),
                        Sex = c.Byte(nullable: false),
                        FaceImgPath = c.String(maxLength: 500),
                        FailedPasswordAttemptCount = c.Int(nullable: false),
                        IsLockedOut = c.Boolean(nullable: false),
                        LastLockoutDate = c.DateTime(),
                        LastLoginDate = c.DateTime(),
                        IsDeleted = c.Boolean(nullable: false),
                        CreatedTime = c.DateTime(nullable: false),
                        UpdatedTime = c.DateTime(),
                        UpdatedBy = c.String(nullable: false, maxLength: 50),
                        CreatedBy = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Role",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 50),
                        RoleName = c.String(nullable: false, maxLength: 50),
                        Description = c.String(maxLength: 200),
                        IsDeleted = c.Boolean(nullable: false),
                        CreatedTime = c.DateTime(nullable: false),
                        UpdatedTime = c.DateTime(),
                        UpdatedBy = c.String(nullable: false, maxLength: 50),
                        CreatedBy = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Permission",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 50),
                        PermissionName = c.String(nullable: false, maxLength: 50),
                        Description = c.String(maxLength: 200),
                        IsMenu = c.Boolean(nullable: false),
                        Action = c.String(maxLength: 100),
                        Controller = c.String(maxLength: 100),
                        Url = c.String(maxLength: 200),
                        CssClass = c.String(maxLength: 200),
                        Order = c.Int(nullable: false),
                        Parent_Id = c.String(maxLength: 50),
                        IsDeleted = c.Boolean(nullable: false),
                        CreatedTime = c.DateTime(nullable: false),
                        UpdatedTime = c.DateTime(),
                        UpdatedBy = c.String(nullable: false, maxLength: 50),
                        CreatedBy = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Permission", t => t.Parent_Id)
                .Index(t => t.Parent_Id);
            
            CreateTable(
                "dbo.RoleAdmins",
                c => new
                    {
                        Role_Id = c.String(nullable: false, maxLength: 50),
                        Admin_Id = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => new { t.Role_Id, t.Admin_Id })
                .ForeignKey("dbo.Role", t => t.Role_Id, cascadeDelete: true)
                .ForeignKey("dbo.Admin", t => t.Admin_Id, cascadeDelete: true)
                .Index(t => t.Role_Id)
                .Index(t => t.Admin_Id);
            
            CreateTable(
                "dbo.PermissionRoles",
                c => new
                    {
                        Permission_Id = c.String(nullable: false, maxLength: 50),
                        Role_Id = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => new { t.Permission_Id, t.Role_Id })
                .ForeignKey("dbo.Permission", t => t.Permission_Id, cascadeDelete: true)
                .ForeignKey("dbo.Role", t => t.Role_Id, cascadeDelete: true)
                .Index(t => t.Permission_Id)
                .Index(t => t.Role_Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.PermissionRoles", "Role_Id", "dbo.Role");
            DropForeignKey("dbo.PermissionRoles", "Permission_Id", "dbo.Permission");
            DropForeignKey("dbo.Permission", "Parent_Id", "dbo.Permission");
            DropForeignKey("dbo.RoleAdmins", "Admin_Id", "dbo.Admin");
            DropForeignKey("dbo.RoleAdmins", "Role_Id", "dbo.Role");
            DropIndex("dbo.PermissionRoles", new[] { "Role_Id" });
            DropIndex("dbo.PermissionRoles", new[] { "Permission_Id" });
            DropIndex("dbo.RoleAdmins", new[] { "Admin_Id" });
            DropIndex("dbo.RoleAdmins", new[] { "Role_Id" });
            DropIndex("dbo.Permission", new[] { "Parent_Id" });
            DropTable("dbo.PermissionRoles");
            DropTable("dbo.RoleAdmins");
            DropTable("dbo.Permission");
            DropTable("dbo.Role");
            DropTable("dbo.Admin");
        }
    }
}
